package com.ivy.irublesson.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.ivy.irublesson.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CContentActivity extends AppCompatActivity {

//    GridView grid;
//    TextView textView;
//    String[] textviews = new String[50];

    private GridView gview;
    private List<Map<String, Object>> data_list;
    private SimpleAdapter sim_adapter;

    private String[] course = {
            "英语veesbsbdsds美术", "英语", "英语", "英语", "英语", "英语", "英语",
            "", "数学代发户籍代价", "数学", "数学", "数学", "数学", "数学",
            "", "语文", "语文", "语文GV手弩isAC", "语文", "语文", "语文",
            "数学", "数学", "数学", "数学", "数学", "数学", "数学",
            "语文", "语文-----------", "语文", "语文", "语文", "语文", "语文",
            "语文", "语文-----------", "语文", "语文", "语文", "语文", "语文"
    };

    ImageView imageView1,imageView2;
    AutoCompleteTextView actv;

    //下拉菜单
    private Spinner sp;
    private List<String> list;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ccontent);

//        initData();
//        List<Map<String,Object>> listItems = new ArrayList<Map<String,Object>>();
//        for (int i = 0;i<textviews.length;i++){
//            Map<String,Object> listItem = new HashMap<String,Object>();
//            listItem.put("text",textviews[i]);
//            listItems.add(listItem);
//        }
//        textView = (TextView) findViewById(R.id.textView);
//        SimpleAdapter simpleAdapter = new SimpleAdapter(this,listItems,R.layout.cell,new String[] {"text"},new int[] {R.id.text1});
//        grid = (GridView) findViewById(R.id.cgrid);
//        grid.setAdapter(simpleAdapter);
//        grid.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
//            @Override
//            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//                textView.setText(textviews[position]);
//            }
//
//            @Override
//            public void onNothingSelected(AdapterView<?> adapterView) {
//
//            }
//        });
//        grid.setOnItemClickListener(new AdapterView.OnItemClickListener(){
//            public void onItemClick(AdapterView<?> parent,View view,int position,long id){
//                textView.setText(textviews[position]);
//            }
//        });

        //隐藏
        imageView1 = (ImageView) findViewById(R.id.cb);
        imageView2 = (ImageView) findViewById(R.id.cyzm);
        actv = (AutoCompleteTextView) findViewById(R.id.cinput);
        imageView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                imageView1.setVisibility(View.GONE);
                imageView2.setVisibility(View.GONE);
                //actv.setVisibility(View.GONE);
                actv.setText("验证码输入正确！！！");
            }
        });

        //课表
        gview = (GridView) findViewById(R.id.cgrid);
        //新建List
        data_list = new ArrayList<Map<String, Object>>();
        //获取数据
        Data(course);
        //新建适配器
        String[] from = {"text"};
        int[] to = {R.id.text};
        sim_adapter = new SimpleAdapter(this, data_list, R.layout.grib_item, from, to);
        //配置适配器
        gview.setAdapter(sim_adapter);


        //下拉栏
        list = new ArrayList<String>();
        list.add("张三");
        list.add("李四");
        list.add("王二");
        list.add("赵一");
        sp = (Spinner) findViewById(R.id.csp);
        final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,list);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        sp.setAdapter(adapter);
        sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(CContentActivity.this,adapter.getItem(position),Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });


        //显示
        sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if ( (list.get(position)) != null){
                    imageView1.setVisibility(View.VISIBLE);
                    imageView2.setVisibility(View.VISIBLE);
                    actv.setText("");
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });
    }

    public List<Map<String, Object>> Data(String[] course) {

        for (int i = 0; i < course.length; i++) {
            Map<String, Object> map = new HashMap<String, Object>();

            map.put("text", course[i]);
            data_list.add(map);
        }
        return data_list;
    }

//    //初始化模拟数据
//    private void initData() {
//        for (int i = 0; i < 42; i++) {
//            textviews[i] = "数学" + i;
//        }
//    }
}
